//
//  IrregularSixShape.m
//  SKPAD
//
//  Created by admin@amonline.com.cn on 15/6/9.
//  Copyright (c) 2015年 amo. All rights reserved.
//

#import "IrregularSixShape.h"

@implementation IrregularSixShape

- (id) initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        _trackLayerBackground = [CAShapeLayer layer];
        _trackLayerBackground.strokeColor = [UIColor blackColor].CGColor;
        UIColor * bgColor = [[UIColor alloc] initWithRed:65.0/255.0 green:72.0/255.0 blue:76.0/255.0 alpha:1];
        _trackLayerBackground.fillColor = bgColor.CGColor;
        _trackLayerBackground.lineCap = kCALineCapRound;
        _trackLayerBackground.bounds = self.bounds;
        _trackLayerBackground.position = CGPointMake(CGRectGetWidth(self.bounds)/2.0, CGRectGetHeight(self.bounds)/2.0);
    
        [self createSomethings];
    }
    return self;
}

- (void) createSomethings
{
    UIBezierPath *pointer = [UIBezierPath bezierPath];
    pointer.lineJoinStyle = kCGLineJoinRound; //终点处理
    pointer.lineCapStyle = kCGLineCapRound;//拐角处理
    pointer.lineWidth = 2;
    
    //拐角左上2
    [pointer addArcWithCenter:CGPointMake(self.frame.size.width * 0.1997, self.frame.size.width * 0.007) radius:self.frame.size.width * 0.007 startAngle:-M_PI endAngle:-M_PI/2 clockwise:YES];
    //顶端直线
    //[pointer moveToPoint:CGPointMake(self.frame.size.width * 0.1997, 0.0)];
    //[pointer addLineToPoint:CGPointMake(self.frame.size.width * 0.993, 0.0)];
    
    //右上拐角
    [pointer addArcWithCenter:CGPointMake(self.frame.size.width * 0.993, self.frame.size.width * 0.007) radius:self.frame.size.width * 0.007 startAngle:-M_PI/2 endAngle:0 clockwise:YES];
    //右侧线
    //[pointer moveToPoint:CGPointMake(self.frame.size.width, self.frame.size.width * 0.007)];
    //[pointer addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.width * 0.007)];
    //[pointer addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height - self.frame.size.width * 0.007)];
    
    //右下拐角
    [pointer addArcWithCenter:CGPointMake(self.frame.size.width * 0.993, self.frame.size.height - self.frame.size.width * 0.007) radius:self.frame.size.width * 0.007 startAngle:0 endAngle:M_PI_2 clockwise:YES];
    
    //底部线
    //[pointer addLineToPoint:CGPointMake(self.frame.size.width * 0.993, self.frame.size.height)];
    //[pointer addLineToPoint:CGPointMake(self.frame.size.width * 0.007, self.frame.size.height)];
    
    //左下拐角
    [pointer addArcWithCenter:CGPointMake(self.frame.size.width * 0.007, self.frame.size.height - self.frame.size.width * 0.007) radius:self.frame.size.width * 0.007 startAngle:M_PI_2 endAngle:M_PI clockwise:YES];
    
    //左侧线
    //[pointer addLineToPoint:CGPointMake(0, self.frame.size.height - self.frame.size.width * 0.007)];
    //[pointer addLineToPoint:CGPointMake(0, self.frame.size.height * 0.1766 + self.frame.size.width * 0.007)];
    
    //左上拐角1
    [pointer addArcWithCenter:CGPointMake(self.frame.size.width * 0.007, self.frame.size.height * 0.1766) radius:self.frame.size.width * 0.007 startAngle:M_PI endAngle:-M_PI/2 clockwise:YES];
    
    //中间横线
    //[pointer addLineToPoint:CGPointMake(self.frame.size.width * 0.007, self.frame.size.height * 0.1766 - self.frame.size.width * 0.007)];
    //[pointer addLineToPoint:CGPointMake(self.frame.size.width * 0.1927 - self.frame.size.width * 0.007, self.frame.size.height * 0.1766 - self.frame.size.width * 0.007)];
    
    //凹槽拐角
    [pointer addArcWithCenter:CGPointMake(self.frame.size.width * 0.1927 - self.frame.size.width * 0.007, self.frame.size.height * 0.1766 - self.frame.size.width * 0.014) radius:self.frame.size.width * 0.007 startAngle:-(M_PI * 2 / 4 * 3)  endAngle:0 clockwise:NO];
    
    //中间竖线
    //[pointer addLineToPoint:CGPointMake(self.frame.size.width * 0.1927, self.frame.size.height * 0.1766 - self.frame.size.width * 0.014)];
    //[pointer addLineToPoint:CGPointMake(self.frame.size.width * 0.1997 - self.frame.size.width * 0.007,  self.frame.size.width * 0.007)];
    
    [pointer closePath];
    //[pointer fill];
    _trackLayerBackground.path = pointer.CGPath;
    
    [self.layer insertSublayer:_trackLayerBackground atIndex:0];
}
@end
